var Instrument=Win.extend({
	p:null,
	name:null,
	runningAction:null,
	runningAction1:null,
	runningAction2:null,
	ctor:function (parent,name,tag) {
		this._super(parent,name,tag);
		this.p=parent;
		this.name=name;
		this.setTag(tag);
		this.initSp();
		this.initAction();
		this.initAction1();
		this.initNumAction();
	},
	initSp:function (){
		//电导仪
		var instrument=new Button(this.main,10,TAG_INSTRUMENT1,"#instrument_back/instrument_back1.png",this.callback,this);
		instrument.setPosition(cc.p(this.main.width*0.75,this.main.height*0.5));
		
		var instrument1=new Button(this.main,10,TAG_INSTRUMENT2,"#Instrument_1.png",this.callback,this);
		instrument1.setPosition(cc.p(this.main.width*0.5, this.main.height*0.5));
		instrument1.setVisible(false);
		
		var battery=new Button(this.main,10,TAG_BATTERY,"#Battery.png",this.callback,this);
		battery.setPosition(cc.p(this.main.width*0.9, this.main.height*0.5));
		battery.setRotation(87);
		battery.setVisible(false);
		
		var occlusion=new Button(this.main,10,TAG_OCCLUSION,"#Instrument_open/Occlusion.png",this.callback,this);
		occlusion.setPosition(cc.p(this.main.width*0.5, this.main.height*0.5));
		occlusion.setVisible(false);
		
		var line=new Button(this.main,10,TAG_LINE,"#line.png",this.callback,this);
		line.setPosition(cc.p(this.main.width*0.615, this.main.height*1.15));
		line.setVisible(false);
		
		var button=new Button(this.main,10,TAG_BUTTON,"#button.png",this.callback,this);
		button.setPosition(cc.p(this.main.width*0.42,this.main.height*0.33));
		button.setVisible(false);
		
		var button1=new Button(this.main,10,TAG_BUTTON1,"#button1.png",this.callback,this);
		button1.setPosition(cc.p(this.main.width*0.56, this.main.height*0.33));
		button1.setVisible(false);
		
		var num=new Button(instrument1,10,TAG_NUM,"#num/num1.png",this.callback,this);
		num.setPosition(cc.p(instrument1.width*0.5,instrument1.height*0.735));
		num.setVisible(false);
	},
	initAction:function(){
		var animFrames=[];
		for(var i=1;i<6;i++){
			var str="instrument_back/instrument_back"+i+".png";
			var frame=cc.spriteFrameCache.getSpriteFrame(str);
			animFrames.push(frame);
		}
		var animation=new cc.Animation(animFrames,0.2) 
		this.runningAction=cc.repeat(cc.animate(animation),1);
		this.runningAction.retain();
	},	
	initAction1:function(){
		var animFrames=[];
		for(var i=1;i<6;i++){
			var str="Instrument_open/open"+i+".png";
			var frame=cc.spriteFrameCache.getSpriteFrame(str);
			animFrames.push(frame);
		}
		var animation=new cc.Animation(animFrames,0.2) 
		this.runningAction1=cc.repeat(cc.animate(animation),1);
		this.runningAction1.retain();
	},
	initNumAction:function(){
		var animFrames=[];
		for(var i=1;i<4;i++){
			var str="num/num"+i+".png";
			var frame=cc.spriteFrameCache.getSpriteFrame(str);
			animFrames.push(frame);
		}
		var animation=new cc.Animation(animFrames,0.2) 
		this.runningAction2=cc.repeat(cc.animate(animation),1);
		this.runningAction2.retain();
	},
	embedded:function(){
		var ber=cc.bezierBy(1, [cc.p(-50,50),cc.p(-125, 75),cc.p(-136,-5)]);
		var occlusion=this.main.getChildByTag(TAG_OCCLUSION);
		var battery=this.main.getChildByTag(TAG_BATTERY);
		battery.runAction(cc.sequence(cc.callFunc(function(){
			battery.setVisible(true);
			occlusion.setVisible(true);
		}, this),ber,cc.callFunc(function() {
			gg.flow.next();
		},this)));
	},
	callback:function(pSender){
		var func=cc.callFunc(function() {
			gg.flow.next();
		},this);
		var action=gg.flow.flow.action;
		var instrument1=this.main.getChildByTag(TAG_INSTRUMENT2);
		var num=instrument1.getChildByTag(TAG_NUM);
		var button=this.main.getChildByTag(TAG_BUTTON);
		var button1=this.main.getChildByTag(TAG_BUTTON1);
		switch (pSender.getTag()) {
		case TAG_INSTRUMENT1:
			var occlusion=this.main.getChildByTag(TAG_OCCLUSION);
			var battery=this.main.getChildByTag(TAG_BATTERY);
		
				if(action==ACTION_DO1){
					pSender.runAction(cc.sequence(cc.callFunc(function() {
						pSender.setPosition(this.main.width*0.5,this.main.height*0.5);
					},this),this.runningAction1,func));
				}else if(action==ACTION_DO2){
					pSender.runAction(cc.sequence(cc.callFunc(function() {
						occlusion.setVisible(false);
						battery.setVisible(false);
					}, this),this.runningAction1.reverse(),cc.delayTime(0.5),cc.callFunc(function() {
						pSender.setPosition(this.main.width*0.75,this.main.height*0.4);
					}, this),this.runningAction.reverse(),func));
				}else{
					pSender.runAction(cc.sequence(this.runningAction,func));
				}
			break;
		case TAG_BUTTON:
			if(action==ACTION_DO1){
				gg.flow.next();
				instrument1.setSpriteFrame("Instrument_2.png");
				num.setVisible(true);
				button1.setVisible(true);
				pSender.setVisible(false);
			}else if(action==ACTION_DO2){
				pSender.runAction(cc.sequence(cc.callFunc(function() {
					instrument1.setSpriteFrame("Instrument_3.png");
					num.setSpriteFrame("num_action/num17.png");
					pSender.setPosition(this.main.width*0.42,this.main.height*0.35);
				},this),func));
			}else if(action==ACTION_DO3){
				pSender.runAction(cc.sequence(cc.callFunc(function() {
					instrument1.setSpriteFrame("Instrument_1.png");
					num.setVisible(false);
				},this),cc.callFunc(function() {
					pSender.setVisible(false);
				},this),func));
			}
			break;
		case TAG_BUTTON1:
			num.runAction(cc.sequence(this.runningAction2,cc.callFunc(function() {
				button.setVisible(true);
				button.setPosition(this.main.width*0.42,this.main.height*0.345);
			},this),func));
			break;
		default:
			break;
		}
	}
});